﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class OnLineLearn : DLL.MyWebPage
{
	/// <summary>
	/// 培训班ID
	/// </summary>
	private int nTrainingID = 0;
	/// <summary>
	/// 课件ID
	/// </summary>
	private int nCoursewareID = 0;
	/// <summary>
	/// 培训班课程ID
	/// </summary>
	private int nTrainingCoursewareID = 0;
	/// <summary>
	/// 培训班控制类
	/// </summary>
	private DLL.Training.Component clsTrainingComp;
	/// <summary>
	/// 培训班课程控制类
	/// </summary>
	private DLL.TrainingCourseware.Component clsTrainingCoursewareComp;
	/// <summary>
	/// 课件控制类
	/// </summary>
	private DLL.Courseware.Component clsCoursewareComp;

	public OnLineLearn()
		: base()
	{
		clsTrainingComp = new DLL.Training.Component(Page);
		clsTrainingCoursewareComp = new DLL.TrainingCourseware.Component(Page);
		clsCoursewareComp = new DLL.Courseware.Component(Page);
	}

	protected void Page_Load(object sender, EventArgs e)
	{
		try
		{
			nTrainingID = Convert.ToInt32(Request["TrainingID"]);
			nCoursewareID = Convert.ToInt32(Request["CoursewareID"]);
			nTrainingCoursewareID = Convert.ToInt32(Request["TrainingCoursewareID"]);
		}
		catch
		{
			nTrainingID = 0;
			nCoursewareID = 0;
			nTrainingCoursewareID = 0;
			TonyNet4V1.ShowMessageAlert.ShowError(Page, "TrainingID传值错误！");
		}

		if (!IsPostBack)
		{
			SetTrainingName();		// 显示培训班名称
			SetTrainingCourseware();		// 显示培训班所有课程
			SetCoursewareName();		// 显示用户正在学习的几次课程
			ShowOnLine();		// 显示视频
		}
	}

	/// <summary>
	/// 显示培训班名称
	/// </summary>
	private void SetTrainingName()
	{
		try
		{
			LabTrainingName.Text = clsTrainingComp.GetOne(nTrainingID).Name;
		}
		catch
		{
			LabTrainingName.Text = "";
		}
	}

	/// <summary>
	/// 显示课程名称
	/// </summary>
	private void SetCoursewareName()
	{
		try
		{
			LabCoursewareName.Text = clsTrainingCoursewareComp.GetOne(nTrainingCoursewareID).NumberName;
		}
		catch
		{
			LabCoursewareName.Text = "";
		}
	}

	/// <summary>
	/// 显示培训班所有课程
	/// </summary>
	private void SetTrainingCourseware()
	{
		List<DLL.TrainingCourseware.Entity> list = new List<DLL.TrainingCourseware.Entity>();

		list = clsTrainingCoursewareComp.QueryByTrainingID(nTrainingID);
		for (int i = 0; i < list.Count; i++)
		{
			HyperLink hLink = new HyperLink();

			hLink.Text = list[i].NumberName;
			hLink.NavigateUrl = "?TrainingID="+nTrainingID.ToString()+"&CoursewareID="+list[i].CoursewareID.ToString()+"&TrainingCoursewareID="+list[i].ID.ToString()+"";

			PCourseware.Controls.Add(hLink);
		}
	}

	/// <summary>
	/// 显示视频
	/// </summary>
	private void ShowOnLine()
	{
		DLL.Courseware.Entity clsCourseware = new DLL.Courseware.Entity();

		clsCourseware = clsCoursewareComp.GetOne(nCoursewareID);

		if (clsCourseware != null)
		{
			iFrame.Attributes.Add("src", "../CuPlay/OnLinePlay.aspx?Path=" + clsCourseware.Path);
			iFrameTime.Attributes.Add("src", "../Admin/CumulativeTime.aspx?TrainingID=" + nTrainingID.ToString());
		}
		iFrame.Attributes.Add("onload", "iFrameHeight('" + iFrame.ClientID.ToString() + "')");
	}
}